import { get, post, put, del } from "@/utils/http";
import type { CreateMenuRequest, UpdateMenuRequest, MenuListResponse, MenuResponse, Menu } from "@/types/menu";
import type { BaseResponse } from "@/types/api";

export const menuApi = {
  // 分页获取菜单列表（支持 name、path、acl）
  getMenus: (params?: { page?: number; pageSize?: number; name?: string; path?: string; acl?: string }) =>
    get<MenuListResponse>("/menus/page", params),

  // 获取全部菜单列表（不分页）
  getAllMenus: () => get<BaseResponse<Menu[]>>("/menus/list"),

  // 获取单个菜单
  getMenu: (id: string) => get<MenuResponse>(`/menus/${id}`),

  // 创建菜单
  createMenu: (data: CreateMenuRequest) => post<MenuResponse>("/menus", data),

  // 更新菜单
  updateMenu: (id: string, data: UpdateMenuRequest) => put<MenuResponse>(`/menus/${id}`, data),

  // 删除菜单
  deleteMenu: (id: string) => del<{ message: string }>(`/menus/${id}`),

  // 根据ACL查询（可选）
  getMenusByAcl: (acl: string) => get<MenuResponse[]>(`/menus/acl/${encodeURIComponent(acl)}`),

  // 根据路径查询（可选）
  getMenuByPath: (path: string) => get<MenuResponse>(`/menus/path/${encodeURIComponent(path)}`),
};
